<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Kra8\Snowflake\HasSnowflakePrimary;

class Order extends Model
{
    //
    use SoftDeletes;
    use HasSnowflakePrimary;

    protected $fillable = [
        'device_style',
        'status',
        'disable_time',
        'member_id',
        'refund_user_id',
        'device_group_id',
        'device_id',
        'time_length',
        'marketing_policy_id',
        'marketing_policy_rule_id',
        'price_specification_id',
        'price_specification_name',
        'price',
        'paid_price',
        'business_name',
        'channel',
        'status',
        'using_time',
        'pay_time',
        'complete_time',
        'platform_open_id',
        'platform_order_no'
    ];
    protected $dates = [
        'using_time',
        'deleted_at',
        'created_at',
        'updated_at',
        'complete_time',
        'pay_time'
    ];
    public $incrementing = false;

    public function wechat_author()
    {
        if ($this->channel === 'WECHAT') {
            return $this->belongsTo('App\Models\Wechat', 'member_id');
        }
        return null;
    }
    public function alipay_author()
    {
        if ($this->channel === 'ALIPAY') {
            return $this->belongsTo('App\Models\Alipay', 'member_id');
        }
        return null;
    }

    public function refund_user()
    {
        return $this->belongsTo('App\Models\User', 'refund_user_id');
    }
    public function device()
    {
        return $this->belongsTo('App\Models\Device', 'device_id');
    }
    public function device_group()
    {
        return $this->belongsTo('App\Models\Group', 'device_group_id');
    }
    public function marketing_policy()
    {
        return $this->belongsTo('App\Models\MarketingPolicy', 'marketing_policy_id');
    }

    public function marketing_policy_rule()
    {
        return $this->belongsTo('App\Models\MarketingPolicyRule', 'marketing_policy_rule_id');
    }

    public function price_specification()
    {
        return $this->belongsTo('App\Models\PriceSpecification', 'price_specification_id');
    }
}
